//
//  ViewController.m
//  纯代码
//
//  Created by student on 16/2/18.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

// 将创建按钮的代码封装成一个方法
- (void)addButtonWithTitle:(NSString *)title andFrame:(CGRect)frame andTag:(int)tag andColor:(UIColor *)color
{
    // 创建按钮
    UIButton *btn = [[UIButton alloc] initWithFrame:frame];
    // 设置按钮文字
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setTitleColor:color forState:UIControlStateNormal];
    //    btn.font = [UIFont systemFontOfSize:50]; //deprecated 过时的属性或方法,在新版本里仍旧可以使用。
    btn.titleLabel.font = [UIFont systemFontOfSize:15];
    btn.tag = tag;
    
    // 添加事件处理
    [btn addTarget:self action:@selector(btnPressed:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:btn];
}



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.lable = [[UILabel alloc] initWithFrame:CGRectMake(50, 200, 200, 50)];
    self.lable.text = @"label";
    self.lable.textColor = [UIColor redColor];
    [self.view addSubview:self.lable];
    [self addButtonWithTitle:@"简单提示框" andFrame:CGRectMake( 10, 50, 100, 50) andTag:1 andColor:[UIColor redColor]];
    [self addButtonWithTitle:@"多按钮" andFrame:CGRectMake( 10, 100, 100, 50) andTag:2 andColor:[UIColor blueColor]];
    [self addButtonWithTitle:@"带输入框" andFrame:CGRectMake( 10, 150, 100, 50) andTag:3 andColor:[UIColor greenColor]];
    [self addButtonWithTitle:@"操作表" andFrame:CGRectMake( 10, 250, 100, 50) andTag:4 andColor:[UIColor blueColor]];
}


-(void)btnPressed:(UIButton *)sender
{
    if(sender.tag == 1)
    {
        UIAlertView *alertView=[[UIAlertView alloc] initWithTitle:@"天下第一帅" message:@"告诉我谁是天下第一帅哦？" delegate:self cancelButtonTitle:@"陈坚大帅比" otherButtonTitles:@"除了陈坚还有谁！！！",nil];
        [alertView show];
    }
    else if(sender.tag==2)
    {
        UIAlertView *alertView=[[UIAlertView alloc] initWithTitle:@"判断" message:@"我长得帅吗" delegate:self cancelButtonTitle:@"帅的" otherButtonTitles:@"超帅",@"非常帅",nil];
        
        [alertView show];
        
    }
    else if (sender.tag==3)
    {
        UIAlertView *alertView=[[UIAlertView alloc] initWithTitle:@"登录" message:@"请输入账号密码" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消",nil];
        alertView.alertViewStyle=UIAlertViewStyleLoginAndPasswordInput;
        [alertView show];
        
    }
    else
    {
        UIActionSheet *sheet=[[UIActionSheet alloc]initWithTitle:@"董大大是大傻逼吗？" delegate:self cancelButtonTitle:@"就是大傻逼" destructiveButtonTitle:@"傻逼傻逼大傻逼" otherButtonTitles:@"傻傻逼傻傻逼",@"傻逼逼逼逼逼",nil];
        [sheet showInView:self.view];
    }
}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSLog(@"点了第几个按钮=%i,按钮的文字是:%@",buttonIndex+1,[alertView buttonTitleAtIndex:buttonIndex]);
    NSLog(@"弹窗的信息是:%@",alertView.title);
    if([alertView.title isEqualToString:@"登录"])
    {
        NSString *info=[NSString stringWithFormat:@"账号:%@ 密码:%@",[alertView textFieldAtIndex:0].text,[alertView textFieldAtIndex:1].text];
        self.lable.text=info;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
